# -*- coding:utf-8 -*-
import codecs
import re


def parser(fp, op1, op2, op3, op4, op5):
    fp = codecs.open(fp, 'r', 'utf8')
    op_train = codecs.open(op1, 'w', 'utf8')
    op_valid = codecs.open(op2, 'w', 'utf8')
    op_test = codecs.open(op3, 'w', 'utf8')
    op_paras = codecs.open(op4, 'w', 'utf8')
    op_target = codecs.open(op5, 'w', 'utf8')
    for line in fp:
        # print(line)
        if line.startswith('@attribute'):
            if line.startswith('@attribute Cluster'):
                print(line)

                m = re.compile('(\{.*\})')
                d = m.sub('', line)
                print("d", d)

                tmp = line.split(',')
            # op_target.write()


def main():
    fp = 'data/cluster_16.arff'
    op_train = 'data/train_16'
    op_valid = 'data/valid_16'
    op_test = 'data/test_16'
    op_paras = 'data/paras'
    op_target = 'data/target'
    parser(fp, op_train, op_valid, op_test, op_paras, op_target)


if __name__ == '__main__':
    main()
